#include <stdio.h>

/* interface */
typedef struct strategy {
    void (*show)(struct strategy *s);
} Strategy;

typedef struct context {
    Strategy *ps;
    void (*set_strategy)(struct context *ctx, Strategy *s);
} Context;

void context_set_strategy(struct context *ctx, Strategy *s) { ctx->ps = s; }

typedef struct strategy_a {
    Strategy s;
} StrategyA;

void strategy_a_show(Strategy *s) { printf("strategy a show\n"); }

typedef struct strategy_b {
    Strategy s;
} StrategyB;

void strategy_b_show(Strategy *s) { printf("strategy b show\n"); }

int main()
{
    Context ctx;
    ctx.set_strategy = context_set_strategy;

    StrategyA strategy_a;
    strategy_a.s.show = strategy_a_show;

    ctx.set_strategy(&ctx, (Strategy *)&strategy_a);
    ctx.ps->show(ctx.ps);

    StrategyB strategy_b;
    strategy_b.s.show = strategy_b_show;

    ctx.set_strategy(&ctx, (Strategy *)&strategy_b);
    ctx.ps->show(ctx.ps);

    return 0;
}
